<template>

  <div id="main"  style="width:1200px;height:600px;" ></div>
</template>

<script>
  import * as echarts from 'echarts';
  export default {
    name: 'chart',
    props:{
      chartData:{
        type:Array,
        default:() =>[]
      }
    },mounted() {
      var chartDom = document.getElementById('main');
      var myChart = echarts.init(chartDom);
      var option;
      setTimeout(function () {

        option = {
          legend: {},
          tooltip: {
            trigger: 'axis',
            showContent: false
          },
          dataset: {
            source: [
              ['product', '视频点赞', '观众投币', '广告收入', '浏览量','其他'],
              ['视频点赞', 56.5, 82.1, 88.7, 70.1, 53.4, 85.1],
              ['观众投币', 51.1, 51.4, 55.1, 53.3, 73.8, 68.7],
              ['广告收入', 40.1, 62.2, 69.5, 36.4, 45.2, 32.5],
              ['浏览量',25 ,35,25,66,58 ],
              ['其他', 25.2, 37.1, 41.2, 18, 33.9, 49.1]
            ]
          },
          xAxis: {type: 'category'},
          yAxis: {gridIndex: 0},
          grid: {top: '55%'},
          series: [
            {type: 'line', smooth: true, seriesLayoutBy: 'row', emphasis: {focus: 'series'}},
            {type: 'line', smooth: true, seriesLayoutBy: 'row', emphasis: {focus: 'series'}},
            {type: 'line', smooth: true, seriesLayoutBy: 'row', emphasis: {focus: 'series'}},
            {type: 'line', smooth: true, seriesLayoutBy: 'row', emphasis: {focus: 'series'}},
            {
              type: 'pie',
              id: 'pie',
              radius: '30%',
              center: ['50%', '25%'],
              emphasis: {focus: 'data'},
              label: {
                formatter: '{b}: {@2012} ({d}%)'
              },
              encode: {
                itemName: 'product',
                value: '2012',
                tooltip: '2012'
              }
            }
          ]
        };
        myChart.on('updateAxisPointer', function (event) {
          var xAxisInfo = event.axesInfo[0];
          if (xAxisInfo) {
            var dimension = xAxisInfo.value + 1;
            myChart.setOption({
              series: {
                id: 'pie',
                label: {
                  formatter: '{b}: {@[' + dimension + ']} ({d}%)'
                },
                encode: {
                  value: dimension,
                  tooltip: dimension
                }
              }
            });
          }
        });
        myChart.setOption(option);

      });

      option && myChart.setOption(option);

    }
  }
</script>

<style></style>
